﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Core.Graphics;
using Core.Graphics.Layers;

namespace WorldEditor.Tiles
{
    public partial class TileLayerManager : UserControl
    {
        public event EventHandler SelectedLayerChanged;

        public TileLayerManager()
        {
            InitializeComponent();
        }

        public void LoadLayers(LayerCollection layers)
        {
            //Remove previous layers
            scLayers.Panel2.Controls.Clear();
            //Load in layers
            foreach (TileLayer tl in layers)
            {
                //Create tile layer props
                LayerProperties tlp = new LayerProperties();
                //Set Tile Layer
                tlp.Layer = tl;
                //Load Props
                tlp.LoadProperties();
                //Get Events
                tlp.PropertiesClicked += new EventHandler(tlp_PropertiesClicked);
                tlp.LayerSelected += new EventHandler(tlp_LayerSelected);
                scLayers.Panel2.Controls.Add(tlp);
            }
        }

        void tlp_LayerSelected(object sender, EventArgs e)
        {
            foreach (LayerProperties tlp in scLayers.Panel2.Controls)
            {
                tlp.BorderStyle = BorderStyle.None;
            }

            TileLayer tl = (TileLayer)sender;

            //tl.BorderStyle = BorderStyle.FixedSingle;

            if (SelectedLayerChanged != null)
                SelectedLayerChanged.Invoke(tl, EventArgs.Empty);
        }

        void tlp_PropertiesClicked(object sender, EventArgs e)
        {
            //Launch real properties window/flyout
        }
    }
}
